package edu.njust.LabSystem.Service;

import edu.njust.LabSystem.dao.IStudentAppointment;
import edu.njust.LabSystem.entity.MybatisUtil;
import edu.njust.LabSystem.entity.StudentAppointment;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class StudentAppointmentService {
	public void insertStudentAppointment(StudentAppointment studentAppointment){
		   SqlSession sqlSession=MybatisUtil.getSqlSession();
		   
		   IStudentAppointment mapper =sqlSession.getMapper(IStudentAppointment.class);
		   
		   Integer result = mapper.insertStudentAppointment(studentAppointment);
		   sqlSession.commit();
		   sqlSession.close();		
	   }
	public List<StudentAppointment> getStudentAppointmentByStudent(String student){

		SqlSession sqlSession=MybatisUtil.getSqlSession();
		
		IStudentAppointment IstudentAppointment=sqlSession.getMapper(IStudentAppointment.class);
		List<StudentAppointment> studentAppointments=IstudentAppointment.getStudentAppointmentByStudent(student);
				
		sqlSession.close();
		
		return studentAppointments;

	}
	
	public Integer deleteStudentAppointment(StudentAppointment studentAppointment){
		   SqlSession sqlSession=MybatisUtil.getSqlSession();
		   
		   IStudentAppointment mapper =sqlSession.getMapper(IStudentAppointment.class);
		   
		   Integer result=mapper.deleteStudentAppointment(studentAppointment);

		   sqlSession.commit();
		   sqlSession.close();		
		   return result;
	   }
	public StudentAppointment getByStudentandExperiment(String uid,String eid) {
		SqlSession sqlSession=MybatisUtil.getSqlSession();
		
		IStudentAppointment IstudentAppointment =sqlSession.getMapper(IStudentAppointment.class);
				
		StudentAppointment studentAppointment=IstudentAppointment.getByStudentandExperiment(uid,eid);
				
		sqlSession.close();
		
		return studentAppointment;
	}
	public List<StudentAppointment> getStudentAppointmentByExperiment(String experiment){
		SqlSession sqlSession=MybatisUtil.getSqlSession();
		
		IStudentAppointment IstudentAppointment=sqlSession.getMapper(IStudentAppointment.class);
		List<StudentAppointment> studentAppointments=IstudentAppointment.getStudentAppointmentByExperiment(experiment);
				
		sqlSession.close();
		
		return studentAppointments;
	}
}
